package ua.com.shootgameserver.configuration;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.Scope;

import ua.com.shootgameserver.entities.Player;
import ua.com.shootgameserver.entities.PlayerImpl;
import ua.com.shootgameserver.protocol.Data;
import ua.com.shootgameserver.protocol.DataImpl;
import ua.com.shootgameserver.server.GameServer;
import ua.com.shootgameserver.server.GameServerImpl;
import ua.com.shootgameserver.session.SessionPlayer;
import ua.com.shootgameserver.session.SessionPlayerImpl;
import ua.com.shootgameserver.utils.SessionTool;
import ua.com.shootgameserver.utils.SessionToolImpl;

import java.util.concurrent.atomic.AtomicInteger;

@Configuration
@PropertySource("classpath:appconfig.properties")
public class CoreConfig {

    @Bean
    @Scope(BeanDefinition.SCOPE_SINGLETON)
    public SessionTool getSessionTool(){
        SessionTool sessionTool = new SessionToolImpl();
        sessionTool.setPlayerId(new AtomicInteger());
        return sessionTool;
    }

	@Bean
	@Scope(BeanDefinition.SCOPE_PROTOTYPE)
	public Player createPlayer(){
        Player player = new PlayerImpl();
        player.setId(getSessionTool().getPlayerId().incrementAndGet());
        return player;
	}

    @Bean
    @Scope(BeanDefinition.SCOPE_PROTOTYPE)
    public SessionPlayer createSessionPlayer(){
        SessionPlayer sessionPlayer = new SessionPlayerImpl();
        sessionPlayer.setPlayer(createPlayer());
        sessionPlayer.setIncomingData(getData());
        sessionPlayer.setOutgoingData(getData());
        return sessionPlayer;
    }
//	
//	@Bean
//	@Scope(BeanDefinition.SCOPE_PROTOTYPE)
//	public Bullet createBullet(){
//		return new Bullet();
//	}
	@Bean
	@Scope(BeanDefinition.SCOPE_SINGLETON)
	public GameServer getGameServer(){
		return new GameServerImpl();
	}

    
    @Bean
    @Scope(BeanDefinition.SCOPE_PROTOTYPE)
    public Data getData(){
        return new DataImpl();
    }
//	
//	@Bean
//	public SomeBean someBean(){
//		return new SomeBeanImpl(); 
//	}
}
